using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

using Spring.Data.NHibernate.Support;
using Spring.Transaction.Interceptor;

using NHibernate;
using NHibernate.Cfg;

using Konekti.Domain.Dao.Interface;
using Konekti.Domain;

namespace Konekti.Domain.Dao.NHibernate
{
    public class HibernateSecUserDao : HibernateDaoSupport, ISecUserDao
    {
        public SecUser FindById(int userId)
        {
            return HibernateTemplate.Load(typeof(SecUser), userId) as SecUser;
        }

        public BindingList<SecUser> FindAll()
        {
            BindingList<SecUser> _SecUsers = new BindingList<SecUser>();

            IList _Result = HibernateTemplate.LoadAll(typeof(SecUser));

            IEnumerator _Enum = _Result.GetEnumerator();
            while (_Enum.MoveNext())
                _SecUsers.Add((SecUser)_Enum.Current);

            return _SecUsers;
        }

        [Transaction(ReadOnly = false)]
        public SecUser Save(SecUser user)
        {
            HibernateTemplate.Save(user);
            return user;
        }

        [Transaction(ReadOnly = false)]
        public SecUser Update(SecUser user)
        {
            HibernateTemplate.Update(user);
            return user;
        }

        [Transaction(ReadOnly = false)]
        public SecUser SaveOrUpdate(SecUser user)
        {
            HibernateTemplate.SaveOrUpdate(user);
            return user;
        }

        [Transaction(ReadOnly = false)]
        public void Delete(SecUser user)
        {
            HibernateTemplate.Delete(user);
        }
    }
}
